package DBLayer;

import java.sql.SQLException;

import ModelLayer.Invoice;

import static org.junit.Assert.*;

import org.junit.Test;

/**
 * @author Gruppe 2
 * 
 */
public class DBInvoiceTest {

	@Test
	public void testinsertInvoice() {
		DBInvoice dbp = new DBInvoice();
		Invoice i = new Invoice(1, "14:05:01");
		try {
			dbp.insertInvoice(i);
		} catch (SQLException e) {
			e.printStackTrace();
			fail("Invoice not inserted");
		}
	}

	@Test
	public void testselectSingleInvoice() throws SQLException {
		DBInvoice dbp = new DBInvoice();
		Invoice i = null;
		try {
			i = dbp.selectSingleInvoice(1);
		} catch (SQLException e) {
			e.printStackTrace();
			fail("Unable to read invoice from DB");
		}
		if (i == null) {
			fail("Invoice not found!");
		}
		System.out.println("Invoice no: " + i.getInvoiceNo()
				+ "  Invoice paymentDate: " + i.getPaymentDate());

	}

	@Test
	public void testUpdateInvoice() {
		DBInvoice dbp = new DBInvoice();
		Invoice i = new Invoice(1, "15:15:55");
		try {
			dbp.updateInvoice(i);
		} catch (SQLException e) {
			e.printStackTrace();
			fail("Unable to update invoice from DB");
		}
	}

}
